#include "Recognizer.h"
#include <assert.h>
#include <iostream>

Recognizer::Recognizer()
{
}

unsigned Recognizer::addModel(const HMM &hmm) {
	models.push_back(hmm);
	return models.size() - 1;
}

HMM& Recognizer::getModel(unsigned index) {
	return models[index];
}

HMM& Recognizer::operator [] (unsigned index) {
	return models[index];
}

unsigned Recognizer::size() const {
	return models.size();
}

unsigned Recognizer::recognize(const Observation& obs) const {
	if (models.size() == 0) {
		return -1;
	}
	double max = -1.0e+10;
	unsigned maxid = 0;
	unsigned n = models.size();
	std::cout << "models.size() = " << n << "\n";
	for (unsigned i = 0; i < n; i++) {
		double t = models[i].logProb(obs);
		std::cout << t << "\n";
		if (t < 0 && t > max) {
			max = t;
			maxid = i;
		}
	}
	return maxid;
}
